package com.zlf.sb.demo.design.chain;

public class ChainStrategyExample {
    public static void main(String[] args) {
        // 创建策略
        RequestStrategy basicStrategy = new BasicUserStrategy();
        RequestStrategy adminStrategy = new AdminUserStrategy();
        RequestStrategy superAdminStrategy = new SuperAdminStrategy();

        // 创建责任链处理者，并设置链条
        RequestHandler basicHandler = new RequestHandlerImpl(basicStrategy);
        RequestHandler adminHandler = new RequestHandlerImpl(adminStrategy);
        RequestHandler superAdminHandler = new RequestHandlerImpl(superAdminStrategy);

        basicHandler.setNextHandler(adminHandler);
        adminHandler.setNextHandler(superAdminHandler);

        // 模拟用户请求
        UserRequest basicRequest = new UserRequest("普通用户", "请求访问资源 A");
        UserRequest adminRequest = new UserRequest("管理员", "请求修改资源 B");
        UserRequest superAdminRequest = new UserRequest("高级管理员", "请求删除资源 C");

        // 处理请求
        System.out.println("处理普通用户请求：");
        basicHandler.handleRequest(basicRequest);

        System.out.println("\n处理管理员请求：");
        adminHandler.handleRequest(adminRequest);

        System.out.println("\n处理高级管理员请求：");
        superAdminHandler.handleRequest(superAdminRequest);
    }
}
